<?php
/**
 * Created by PhpStorm.
 * User: wumengmeng <wu_mengmeng@foxmail.com>
 * Date: 2019/4/26 0026
 * Time: 14:35
 */

namespace HiCommon\Service;

use HiCommon\Repository\CheckpointMakeDateRepository;
use HiCommon\Repository\OrderCheckpointRepository;
use HiCommon\Repository\ShopCountRepository;

class ShopCheckpointService extends BaseService
{

//    /**
//     * 检测站-首页数据-商户端
//     *
//     * @param int $n_shop_id
//     *
//     * @return array
//     * @throws \Exception
//     * @author wumengmeng <wu_mengmeng@foxmail.com>
//     */
//    public function api_index($n_shop_id = 0){
//        //查询检测站昨天、今天两日收益数据
//        $arr_data = [];
//        $s_start_date = date('Y-m-d',strtotime('yesterday'));
//        $s_end_date = date('Y-m-d');
//        $arr_date = ['start'=>$s_start_date,'end'=>$s_end_date];
//
//        $arr_search['shop_id'] = $n_shop_id;
//        $result = ShopService::api_shop_finance_index($arr_search);
//
//        $result = ShopCheckpointService::get_shop_profit_data($n_shop_id,$arr_date);
//        if($result['state'] == 0){
//            $arr_data['yesterday'] = $result['data'][$s_start_date];
//            $arr_data['today'] = $result['data'][$s_end_date];
//        }
//
//        //接单数量
//        $arr_where['shop_id'] = $n_shop_id;
//        $arr_where['pay_state'] = 2;
//        $arr_where['appointment_state'] = 2;
//        $arr_where['complete_state'] = -1;
//        $result = OrderCheckpointRepository::get_count_by_where($arr_where);
//        $arr_data['checkpoint_waiting_order_num'] = $result;
//        return  hello_success('成功',$arr_data);
//
//    }

//    /**
//     * 获取[检测站]-[指定门店]指定[日期区间]收益数据
//     *
//     * @param $n_shop_id
//     * @param $arr_date
//     *
//     * @return array
//     * @throws \Exception
//     * @author wumengmeng <wu_mengmeng@foxmail.com>
//     */
//    public function get_shop_profit_data($n_shop_id,$arr_date){
//
//        //检测站只有年检预约单 收益只统计年检预约
//        $arr_date_range = get_date_from_range($arr_date);
//        if(empty($arr_date_range)){
//            return hello_error('日期区间错误');
//        }
//        $arr_dates = $arr_date_range['dates'];//日期区间
//        rsort($arr_dates);
//        $res_take_num = ShopCountRepository::ck_order_take_num_by_date_block($arr_date,['shop_id'=>$n_shop_id]);//指定日期接单总数
//        $res_pay_price = ShopCountRepository::ck_pay_price_by_date_block($arr_date,['shop_id'=>$n_shop_id]);//指定日期总交易额度
//        $res_refund_price = ShopCountRepository::ck_refund_price_by_date_block($arr_date,['shop_id'=>$n_shop_id]);//指定日期退款额度
//        $arr_data = [];
//        foreach ($arr_dates as $value)
//        {
//            $n_num = intval($res_take_num->where('date',$value)->first()->num);
//            $n_pay_price = number_format_money($res_pay_price->where('date',$value)->first()->pay_price);
//            $n_refund_price = number_format_money($res_refund_price->where('date',$value)->first()->refund_price);
//            $n_profit = bcsub($n_pay_price,$n_refund_price,2);
//            $arr_data[$value] = [
//              'date'=>$value,
//              'pay_price'=>$n_pay_price,
//              'refund_price'=>$n_refund_price,
//              'profit'=>$n_profit,
//              'num'=>$n_num
//            ];
//        }
//        return  hello_success('成功',$arr_data);
//    }


//    /**
//     * 检测站-收益明细
//     *
//     * @param int    $n_shop_id
//     * @param string $s_start_date  开始日期
//     * @param string $s_end_date    结束日期
//     * @param string $s_date_type   展示日期类型  默认 每日 Ymd每日 Ym每月 Y每年
//     *
//     * @return array
//     * @throws \Exception
//     * @author wumengmeng <wu_mengmeng@foxmail.com>
//     */
//    public function api_profit_index($n_shop_id = 0,$s_start_date = '',$s_end_date = '',$s_date_type = ''){
//        //查询检测站收益明细数据
//        $arr_date['start'] = $s_start_date;
//        $arr_date['end'] = $s_end_date;
//        $arr_date['date_type'] = $s_date_type;
//        $res = ShopCheckpointService::get_shop_profit_data($n_shop_id,$arr_date);
//        if($res['state'] == 0){
//            $res['data'] = array_values($res['data']);
//        }
//        return  $res;
//    }

//    /**
//     * 检测机构近期图表统计数据
//     *
//     * @param $arr_date
//     * @param $n_shop_id
//     *
//     * @return array
//     * @throws \Exception
//     * @author wumengmeng <wu_mengmeng@foxmail.com>
//     */
//    public function api_graphs_statistics($arr_date,$n_shop_id){
//        $arr_date_range = get_date_from_range($arr_date);
//        if(empty($arr_date_range)){
//            return hello_error('日期区间错误');
//        }
//        $arr_dates = $arr_date_range['dates'];//日期区间
//        sort($arr_dates);
//
//        //指定日期接单总数
//        $arr_search = ['shop_id'=>$n_shop_id];
//        $res_order_num = ShopCountRepository::ck_order_take_num_by_date_block($arr_date,$arr_search);
//
//        //指定日期自驾接单总数
//        $arr_search = ['shop_id'=>$n_shop_id,'is_call_helpdriving'=>2];
//        $res_zijia_order_num = ShopCountRepository::ck_order_take_num_by_date_block($arr_date,$arr_search);
//
//        //指定日期自驾接单总数
//        $arr_search = ['shop_id'=>$n_shop_id,'is_call_helpdriving'=>1];
//        $res_daijia_order_num = ShopCountRepository::ck_order_take_num_by_date_block($arr_date,$arr_search);
//
//        //指定日期总交易额度
//        $arr_search = ['shop_id'=>$n_shop_id];
//        $res_pay_price = ShopCountRepository::ck_pay_price_by_date_block($arr_date,$arr_search);
//
//        //指定日期退款额度
//        $arr_search = ['shop_id'=>$n_shop_id];
//        $res_refund_price = ShopCountRepository::ck_refund_price_by_date_block($arr_date,$arr_search);
//
//        $arr_data = [];
//        foreach ($arr_dates as $value)
//        {
//            $n_num = intval($res_order_num->where('date',$value)->first()->num);
//            $n_zijia_num = intval($res_zijia_order_num->where('date',$value)->first()->num);
//            $n_daijia_num = intval($res_daijia_order_num->where('date',$value)->first()->num);
//            $n_pay_price = number_format_money($res_pay_price->where('date',$value)->first()->pay_price);
//            $n_refund_price = number_format_money($res_refund_price->where('date',$value)->first()->refund_price);
//            $n_profit = bcsub($n_pay_price,$n_refund_price,2);
//            $arr_data['date'][] = $value;
//            $arr_data['num'][] = $n_num;
//            $arr_data['zijia_num'][] = $n_zijia_num;
//            $arr_data['daijia_num'][] = $n_daijia_num;
//            $arr_data['pay_price'][] = $n_pay_price;
//            $arr_data['refund_price'][] = $n_refund_price;
//            $arr_data['profit'][] = $n_profit;
//        }
//
//        //时间区间内总接单数
//        $n_total = intval($res_order_num->sum('num'));
//        $arr_data['total'] = $n_total;
//        $arr_data['cate'] = 1;
//
//        return  hello_success('查询成功',$arr_data);
//
//    }

    /**
     * 检测机构-近期预约日期列表
     *
     * @param int $n_shop_id
     *
     * @return mixed
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function api_checkpoint_appointment_day_nearly($n_shop_id = 0){
        $res = CheckpointMakeDateRepository::appointment_days_nearly($n_shop_id);
        $data = $res->toarray();
        return  hello_success('成功',$data);
    }

}